package com.quartet.modules.vehicle.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quartet.modules.alarm.dto.TFatigueDrivingAlarmInfoResponseDto;
import com.quartet.modules.alarm.entity.TFatigueDrivingAlarmInfo;
import com.quartet.modules.customer.dao.TCustomerInfoDao;
import com.quartet.modules.customer.entity.TCustomerInfo;
import com.quartet.modules.vehicle.dao.TDriverInfoDao;
import com.quartet.modules.vehicle.dao.TVehicleInfoDao;
import com.quartet.modules.vehicle.dao.TVehicleOwnerInfoDao;
import com.quartet.modules.vehicle.dao.TVehicleStatusInfoDao;
import com.quartet.modules.vehicle.dto.TVehicleStatusInfoResponseDto;
import com.quartet.modules.vehicle.entity.TDriverInfo;
import com.quartet.modules.vehicle.entity.TVehicleInfo;
import com.quartet.modules.vehicle.entity.TVehicleOwnerInfo;
import com.quartet.modules.vehicle.entity.TVehicleStatusInfo;
import com.quartet.modules.vehicle.service.TVehicleStatusInfoService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 车辆告警信息表(TVehicleStatusInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-05-18 10:39:04
 */
@Service("tVehicleStatusInfoService")
public class TVehicleStatusInfoServiceImpl extends ServiceImpl<TVehicleStatusInfoDao, TVehicleStatusInfo> implements TVehicleStatusInfoService {

    @Autowired
    private TVehicleInfoDao tVehicleInfoDao;

    @Autowired
    private TCustomerInfoDao tCustomerInfoDao;

    /**
     * 服务对象
     */
    @Resource
    private TVehicleOwnerInfoDao tVehicleOwnerInfoDao;

    /**
     * 服务对象
     */
    @Resource
    private TDriverInfoDao tDriverInfoDao;


//    /**
//     * 功能描述: 获取状态表信息
//     * @author huipanxing huipanxing@chinasofti.com
//     * @date 2021/5/18 10:47
//     * @param tVehicleAlarmInfoRequestDto
//     * @return java.util.List<com.quartet.modules.vehicle.dto.TVehicleStatusInfoResponseDto>
//     */
//    @Override
//    public List<TVehicleStatusInfoResponseDto> selectVehicleStatusInfo(TVehicleAlarmInfoRequestDto tVehicleAlarmInfoRequestDto) {
//        QueryWrapper<TVehicleStatusInfo> queryWrapper = new QueryWrapper<>();
//        if (!ObjectUtils.isEmpty(tVehicleAlarmInfoRequestDto.getTabType())) {
//            queryWrapper.lambda().eq(TVehicleStatusInfo::getVehicleStatus, tVehicleAlarmInfoRequestDto.getTabType());
//        }
//
//        if (!ObjectUtils.isEmpty(tVehicleAlarmInfoRequestDto.getVehicleStatus())) {
//            queryWrapper.lambda().eq(TVehicleStatusInfo::getOnlineStatus, tVehicleAlarmInfoRequestDto.getVehicleStatus());
//        }
//
//        if (!ObjectUtils.isEmpty(tVehicleAlarmInfoRequestDto.getQueryType()) && (!ObjectUtils.isEmpty(tVehicleAlarmInfoRequestDto.getQueryValue()))) {
//            queryWrapper.eq(tVehicleAlarmInfoRequestDto.getQueryType(), tVehicleAlarmInfoRequestDto.getQueryValue());
//        }
//        List<TVehicleStatusInfo> tVehicleStatusInfoList = this.baseMapper.selectList(queryWrapper);
//        List<TVehicleStatusInfoResponseDto> tVehicleStatusInfoResponseDtoList = tVehicleStatusInfoList.stream().map(tVehicleStatusInfo -> {
//            TVehicleStatusInfoResponseDto tVehicleStatusInfoResponseDto = BeanUtil.copyProperties(tVehicleStatusInfo, TVehicleStatusInfoResponseDto.class);
//            QueryWrapper<TVehicleInfo> queryWrapper1 = new QueryWrapper<>();
//            queryWrapper1.lambda().eq(TVehicleInfo::getVehicleCode, tVehicleStatusInfoResponseDto.getVehicleCode());
//            TVehicleInfo tVehicleInfo = tVehicleInfoDao.selectOne(queryWrapper1);
//            if (ObjectUtils.isEmpty(tVehicleInfo)) {
//                return tVehicleStatusInfoResponseDto;
//            }
//            tVehicleStatusInfoResponseDto.setCarNumber(tVehicleInfo.getCarNumber());
//            tVehicleStatusInfoResponseDto.setCarNumberColor(tVehicleInfo.getLicensePlateColor());
//            tVehicleStatusInfoResponseDto.setEquipmentCode(tVehicleInfo.getEquipmentCode());
//            tVehicleStatusInfoResponseDto.setFlowCardNumber(tVehicleInfo.getFlowCardNumber());
//            tVehicleStatusInfoResponseDto.setCustomerCode(tVehicleInfo.getCustomerCode());
//
//            QueryWrapper<TVehicleOwnerInfo> queryWrapper2=new QueryWrapper();
//            queryWrapper2.lambda().eq(TVehicleOwnerInfo::getVehicleCode,tVehicleStatusInfoResponseDto.getVehicleCode());
//            TVehicleOwnerInfo tVehicleOwnerInfo = tVehicleOwnerInfoDao.selectOne(queryWrapper2);
//            if (ObjectUtils.isEmpty(tVehicleOwnerInfo)) {
//                return tVehicleStatusInfoResponseDto;
//            }
//            tVehicleStatusInfoResponseDto.setOwnersName(tVehicleOwnerInfo.getOwnersName());
//            tVehicleStatusInfoResponseDto.setOwnerPhone(tVehicleOwnerInfo.getOwnerPhone());
//
//            QueryWrapper<TDriverInfo> queryWrapper3=new QueryWrapper();
//            queryWrapper3.lambda().eq(TDriverInfo::getVehicleCode,tVehicleStatusInfoResponseDto.getVehicleCode());
//            TDriverInfo tDriverInfo = tDriverInfoDao.selectOne(queryWrapper3);
//            if (ObjectUtils.isEmpty(tDriverInfo)) {
//                return tVehicleStatusInfoResponseDto;
//            }
//            tVehicleStatusInfoResponseDto.setDriverName(tDriverInfo.getDriverName());
//            tVehicleStatusInfoResponseDto.setDriverPhone(tDriverInfo.getDriverPhone());
//
//            QueryWrapper<TCustomerInfo> queryWrapper4 = new QueryWrapper<>();
//            queryWrapper4.lambda().eq(TCustomerInfo::getCustomerCode, tVehicleStatusInfoResponseDto.getCustomerCode());
//            TCustomerInfo tCustomerInfo = tCustomerInfoDao.selectOne(queryWrapper4);
//            if (ObjectUtils.isEmpty(tCustomerInfo)) {
//                return tVehicleStatusInfoResponseDto;
//            }
//            tVehicleStatusInfoResponseDto.setCustomerName(tCustomerInfo.getCustomerName());
//            return tVehicleStatusInfoResponseDto;
//        }).filter(tVehicleStatusInfoResponseDto -> tVehicleAlarmInfoRequestDto.getCustomerCodeList().contains(tVehicleStatusInfoResponseDto.getCustomerCode())).collect(Collectors.toList());
//        return tVehicleStatusInfoResponseDtoList;
//    }
}